package cn.xorange.commons.core.exception;

import cn.xorange.commons.core.basic.bean.SystemCode;
import cn.xorange.commons.utils.exception.BaseException;
import cn.xorange.commons.utils.lang.StringUtils;

/**
 * @author : yangjian
 * @date : 2024/1/1
 */
public class SysException extends BaseException {

    public SysException(SystemCode code){
        super(code.getStatus(), code.getCode(), code.getMsg());
    }
    public SysException(SystemCode code, RuntimeException e) {
        super(code.getStatus(), code.getCode(), code.getMsg(), e);
    }

    public static SysException error(String msg){
        SystemCode code = SystemCode.SYSTEM_EXCEPTION;
        code.setMsg(msg);
        return new SysException(code);
    }

    public static SysException paramException(String msg){
        SystemCode code = SystemCode.SYSTEM_PARAM_EXCEPTION;
        code.setMsg(msg);
        return new SysException(code);
    }

    public static SysException paramException(){
        SystemCode code = SystemCode.SYSTEM_PARAM_EXCEPTION;
        return new SysException(code);
    }

    /**
     * URL 路径错误
     */
    public static SysException pathNotFound(String url){
        SystemCode code = SystemCode.SYSTEM_PATH_NOT_FOUND;
        code.setMsg(StringUtils.format("URL：{} ,路径不存在",url));
        return new SysException(code);
    }

    /**
     * 空指针异常
     * @param throwable Throwable
     */
    public static SysException nullPointException(RuntimeException e){
        return new SysException(SystemCode.SYSTEM_NULL_POINT_EXCEPTION,e);
    }

}
